package com.baihan.angus.app.game.busshow.adps;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.baihan.angus.app.game.basic.base.BaseAdp;
import com.baihan.angus.app.game.busshow.R;
import com.baihan.angus.app.game.common.bean.response.DmScriptResponse;

public class ScriptAdp extends BaseAdp<DmScriptResponse.DataXX.DataX, ScriptAdp.ViewHolder> {

    private OnItemClickListener mOnItemClickListener;

    @Override
    protected RecyclerView.ViewHolder createYourViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_dm_script, parent, false);
        return new ViewHolder(view);
    }

    @Override
    protected void bindYourViewHolder(@NonNull ViewHolder holder, int position) {
        ViewHolder vh = holder;

        DmScriptResponse.DataXX.DataX item = getItem(position);

        vh.tvTitle.setText(item.getTitle());

        if (item.getIs_send() == 0) {
            vh.tvSendScript.setEnabled(true);
        } else {
            vh.tvSendScript.setEnabled(false);
        }

        vh.tvSendScript.setOnClickListener(v -> {
            mOnItemClickListener.onSend(position);
        });
    }

    @Override
    protected int getEmptyView() {
        return 0;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        TextView tvTitle, tvSendScript;
        ImageView ivScript;
        LinearLayout llScriptItem;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvTitle = itemView.findViewById(R.id.tvTitle);
            tvSendScript = itemView.findViewById(R.id.tvSendScript);
            ivScript = itemView.findViewById(R.id.ivScript);
            llScriptItem = itemView.findViewById(R.id.llScriptItem);
        }
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onSend(int position);
    }
}
